<?php

namespace app\common\cachemodel\chat;

use app\common\model\BaseCache;
use think\Log;

class HzChatRecordDetailsZan extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.hz_chat_record_details_zan';

    /**
     * 设置 赞同与反对
     * @param int $uid
     * @param int $chatDetailId
     * @param int $status
     * @param string $feedbackReason 反馈原因
     * @return bool
     */
    public function setZan(int $uid, int $chatDetailId, int $status, string $feedbackReason)
    {
        try
        {
            $id = $this->where(['uid' => $uid, 'chat_detail_id' => $chatDetailId])->value('id');

            if ($id)
            {
                $this->where('id', $id)->update(['status' => $status, 'feedback' => $feedbackReason, 'update_time' => time()]);
            } else
            {
                $this->insertGetId([
                    'uid' => $uid,
                    'chat_detail_id' => $chatDetailId,
                    'status' => $status,
                    'feedback' => $feedbackReason,
                    'create_time' => time()
                ]);
            }

            return true;
        }
        catch (\Exception $e)
        {
            Log::write('HzChatRecordDetailsZan model => setZan()异常：' . $e->getMessage() . '失败行数：' . $e->getLine(), 'error');
            return false;
        }
    }
}